package com.itheima.reggie.service.impl;

import com.itheima.reggie.entity.User;
import com.itheima.reggie.mapper.UserMapper;
import com.itheima.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired(required = false)
    private UserMapper userMapper;

    @Override
    public User login(String phone, String code, String codeInSession) {
//1. 校验验证码是否为空并且两个验证码是否一致
        User dbUser = null;
        if(codeInSession!=null && codeInSession.equalsIgnoreCase(code)){
           dbUser= userMapper.findByPhone(phone);
           if(dbUser==null){
              dbUser= new User();
              dbUser.setStatus(1);
              dbUser.setPhone(phone);
              userMapper.save(dbUser);
           }
        }
        return dbUser;
    }
}
